﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using com.dz.common;
namespace com.dz.components.background
{
    public class BookICONCatchManager
    {
        DataManager m_data_mgr = new DataManager();
        FileManager m_file_mgr = new FileManager();
        string m_icon_url_qidian = "http://image.cmfu.com/books/{0}/{0}.jpg";
        /// <summary>
        /// 下载小说封面
        /// </summary>
        public void StartCatchICON()
        {
            DataSet ds = m_data_mgr.GetExistsImageBookList((int)Consts.Site.qidian);
            if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
                return;

            long t_book_id = 0;
            string t_site_book_id = string.Empty;

            try
            {

                for (int index = 0; index < ds.Tables[0].Rows.Count; index++)
                {
                    if (!long.TryParse(ds.Tables[0].Rows[index]["bookId"].ToString(), out t_book_id))
                        t_book_id = 0;

                    t_site_book_id = ds.Tables[0].Rows[index]["oldBookId"].ToString();

                    BookSiteManager.DownLoadImage(string.Format(m_icon_url_qidian, t_site_book_id),  t_book_id);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("下载小说封面失败" + ex.ToString());
            }
        }
    }
}
